package com.shell.governor.user.rx;

import com.shell.bee.base.exception.UnCheckException;
import com.shell.bee.base.utils.JsonUtil;
import com.shell.bee.base.utils.SpringContextUtil;
import com.shell.feign.ContractTransferFeigh;
import com.shell.framework.rx.OnErrorNotImplementedSubscriber;
import com.shell.governor.user.UserEvent;
import com.shell.governor.user.po.PubUser;
import com.shell.governor.user.po.PubUserOpt;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class SyncUserToContractSubscriber extends OnErrorNotImplementedSubscriber<UserEvent> {
	@Autowired
	ContractTransferFeigh contractTransferFeigh;

	public void onApplicationEvent(UserEvent event) {
		PubUser user = event.getUser();
		PubUserOpt opt = event.getUserOpt();
		if ((event.isNeedApprover()) && (event.getUserOpt().getBizCode().equals("0"))) {
			return;
		}
		if ("on".equals(SpringContextUtil.getProperty("contract.switch"))) {
			String userJson = null;
			try {
				userJson = JsonUtil.toJson(user);
			} catch (Exception e) {
				throw new UnCheckException("user json ��������");
			}
			this.contractTransferFeigh.personalUserSync(userJson);
			this.contractTransferFeigh.signerActiveSyncByUser(opt.getEntId(), userJson);
		}
	}
}
